package cn.hallele.leinsteining.ms.auditcenter.entity;

import jakarta.persistence.*;
import lombok.*;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * LogEntity
 *
 * @author anle5
 * @since 2024/8/4 20:17
 */
@Getter
@Setter
@Entity
@Table(name = "ac_log")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class LogEntity implements Serializable {
    @Serial
    private static final long serialVersionUID = 617788715414718573L;

    /**
     * 身份唯一标识
     * 生成策略: 从表key_generator中读取
     * name: TableGenerator唯一标识
     * pkColumnName：生成策略所对应键值的名称
     * pkColumnValue：键当前所生成的值，它的值将会随着每次创建累加
     * initialValue: 初始值
     * allocationSize: 递增至
     */
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "LogEntity")
    @TableGenerator(name = "LogEntity",
            table = "key_generator",
            pkColumnName = "gen_name",
            valueColumnName = "gen_value",
            pkColumnValue = "ac_log",
            initialValue = 1,
            allocationSize = 1
    )
    @Column(name = "id")
    private Long id;

    /**
     * 微服务名字
     */
    @Column(name = "app_name")
    private String appName;

    /**
     * 接口id
     */
    @Column(name = "api_id")
    private String apiId;

    /**
     * 追踪日志
     */
    @Column(name = "trance_id")
    private String tranceId;

    /**
     * 请求IP
     */
    @Column(name = "ip")
    private String ip;

    /**
     * 请求设备信息
     */
    @Column(name = "device")
    private String device;

    /**
     * 接口调用者
     */
    @Column(name = "initiator")
    private Long initiator;

    /**
     * 请求内容，base64加密
     */
    @Column(name = "request")
    private String request;

    /**
     * 响应内容，base64加密
     */
    @Column(name = "response")
    private String response;

    /**
     * 请求开始时间
     */
    @Column(name = "request_start_time")
    private LocalDateTime requestStartTime;

    /**
     * 请求结束时间
     */
    @Column(name = "request_end_time")
    private LocalDateTime requestEndTime;

    /**
     * 创建时间
     */
    @Column(name = "create_time")
    private LocalDateTime createTime;

    /**
     * 创建者
     */
    @Column(name = "create_by")
    private Long createBy;
}
